enum PIN1 {
    //% block="P0"
    1,
    //% block="P1"
    2,
}

enum PIN2 {
    //% block="P1"
    2,
    //% block="P0"
    1,
}

//% color="#9F32F1" iconWidth=50 iconHeight=40
namespace MP3 {

    //% block="init port Rx[PIN1] Tx[PIN2]" blockType="command"    
    //% PIN1.shadow="dropdown" PIN1.options="PIN1" PIN1.defl="1"
    //% PIN2.shadow="dropdown" PIN2.options="PIN2" PIN2.defl="2"
    export function init(parameter: any, block: any) {
        let Rx = parameter.PIN1.code;
        let Tx = parameter.PIN2.code;
        Generator.addInclude("MyAudioLibrary", "#include <MyAudioLibrary.h>");
        Generator.addObject(`int`, `MyAudioLibrary`, `audio(Serial1);`);
        Generator.addSetup(`begin`, `Serial1.begin(9600, SERIAL_8N1, ${Rx}, ${Tx});`);       
    }


    //% block="set volume [volume]" blockType="command"    
    //% volume.shadow="string" volume.defl=50
    //% volume.shadow="range" volume.params.min=0 volume.params.max=100 volume.defl=50
    export function volume(parameter: any, block: any) {
        let volume = parameter.volume.code;
        Generator.addCode(`audio.volume(${volume});`);
    }

    //% block="play music[numnn]" blockType="command"    
    //% numnn.shadow="normal" numnn.defl=1
    export function play2(parameter: any, block: any) {
        let numnn = parameter.numnn.code;
        Generator.addCode(`audio.play(${numnn}); `);
        //Generator.addCode(`audio.play(atoi(${numnn})); `);
    }
}

